package com.kevinxiaoge.ruoli.bean;

import com.kevinxiaoge.ruoli.exception.BaseException;
import org.springframework.util.ObjectUtils;

import java.time.Instant;
import java.util.HashMap;

/**
 * @author chengyuanyuan
 */
public class ErrorReponse {

    private int code;

    private int status;

    private String message;

    private String path;

    private Instant timestamp;

    private HashMap<String, Object> data = new HashMap<>();

    public ErrorReponse() {
    }

    public ErrorReponse(BaseException ex, String path) {
        this(ex.getError().getCode(), ex.getError().getStatus().value(), ex.getError().getMessage(), path, ex.getData());
    }

    public ErrorReponse(int code, int status, String message, String path, HashMap<String, Object> data) {
        this.code = code;
        this.status = status;
        this.message = message;
        this.path = path;
        this.timestamp = Instant.now();
        if (!ObjectUtils.isEmpty(data)) {
            this.data.putAll(data);
        }
    }
}
